<template>
  <div class="app-container">

    <!-- <div class="app-container-title">
      <OverView />
    </div> -->

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="计划编码" prop="planCode">
        <el-input
          v-model="queryParams.planCode"
          placeholder="请输入计划编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划名称" prop="planName">
        <el-input
          v-model="queryParams.planName"
          placeholder="请输入计划名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="来源单据" prop="sourceCode">
        <el-input
          v-model="queryParams.sourceCode"
          placeholder="请输入来源单据"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item label="产品编号" prop="proCode">
        <el-input
          v-model="queryParams.proCode"
          placeholder="请输入产品编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="protName">
        <el-input
          v-model="queryParams.proName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="工单类型" prop="workorderType">
        <el-input
          v-model="queryParams.workorderType"
          placeholder="请选择工单类型"
          clearable
          @keyup.enter.native="handleQuery"
        />

      </el-form-item> -->
      <el-form-item label="需求日期" prop="deadLine">
        <el-date-picker clearable
          v-model="queryParams.deadLine"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择需求日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:po:plan:edit']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:pro:workorder:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:pro:workorder:edit']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes:po:plan:edit']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <vxe-table
      border
      stripe
      ref="tableRef"
      size="small"
      header-align="center"
      :row-config="rowConfig"
      :column-config="columnConfig"
      @cell-click="handleRowClick"
      v-loading="loading"
      :data="tableData"
      height="520"
    >
      <vxe-column field="planCode" width="200" show-overflow="title" align="center" title="计划编码" drag-sort></vxe-column>
      <vxe-column field="planName" width="200" show-overflow="title" align="center" title="计划名称"></vxe-column>
      <vxe-column field="proCode" width="200" show-overflow="title" align="center" title="产品编码"></vxe-column>
      <vxe-column field="proName" width="200" show-overflow="title" align="center" title="产品名称"></vxe-column>
      <!-- <vxe-column field="orderSource" width="200" show-overflow="title" align="center" title="订单类型">
        <template #default="{ row }">
          <dict-tag :options="dict.type.mes_order_status" :value="row.orderSource"/>
        </template>
      </vxe-column> -->
      <vxe-column field="orderCode" width="200" show-overflow="title" align="center" title="订单编号"></vxe-column>
      <vxe-column field="planCount" width="200" show-overflow="title" align="center" title="计划需求数"></vxe-column>
      <vxe-column field="outputCount" width="200" show-overflow="title" align="center" title="已生产数量"></vxe-column>
      <!-- <vxe-column field="planStatus" width="160" show-overflow="title" align="center" title="计划进展">
        <template #default="{ row }">
          <dict-tag :options="dict.type.mes_workorder_sourcetype" :value="row.planStatus"/>
        </template>
      </vxe-column> -->
      <vxe-column field="unitOfMeasure" width="100" show-overflow="title" align="center" title="单位"></vxe-column>
      <vxe-column width="100" show-overflow="title" align="center" title="开工日期">
        <template #default="{ row }">
          <span>{{ parseTime(row.startTime,'{y}-{m}-{d}') }}</span>
        </template>
      </vxe-column>
      <vxe-column width="100" show-overflow="title" align="center" title="完工日期">
        <template #default="{ row }">
          <span>{{ parseTime(row.endTime,'{y}-{m}-{d}') }}</span>
        </template>
      </vxe-column>
      <vxe-column width="100" show-overflow="title" align="center" title="需求日期">
        <template #default="{ row }">
          <span>{{ parseTime(row.deadLine,'{y}-{m}-{d}') }}</span>
        </template>
      </vxe-column>
      <vxe-column field="remark" width="200" align="center" title="备注"></vxe-column>
      <vxe-column width="300" align="center" title="操作" fixed="right">
        <template #default="{ row }">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-show="row.planStatus!=='finished'&&row.planStatus!=='closed'"
            @click="handleUpdate(row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            style="color:#67c23a"
            icon="el-icon-back"
            v-show="row.planStatus=='decomposed'"
            @click="handleWithdrawPlan(row)"
          >撤回</el-button>
          <el-button
            size="mini"
            type="text"
            style="color:#e6a23c"
            icon="el-icon-refresh"
            v-show="row.planStatus=='undecomposed'||row.planStatus=='withdraw'"
            @click="handleDecomposePlan(row)"
          >分解</el-button>
          <el-button
            size="mini"
            type="text"
            style="color:#f56c6c"
            icon="el-icon-circle-close"
            v-show="row.planStatus!=='finished'&&row.planStatus!=='closed'"
            @click="handleClosePlan(row)"
          >关闭</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            v-show="row.planStatus!=='finished'&&row.planStatus!=='closed'"
            @click="handleFinishPlan(row)"
          >完成</el-button>
          <el-button
            size="mini"
            type="text"
            style="color:#f56c6c"
            icon="el-icon-delete"
            v-show="row.planStatus=='undecomposed'||row.planStatus=='withdraw'"
            @click="handleDelete(row)"
          >删除</el-button>
        </template>
      </vxe-column>
    </vxe-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <div class="app-container-footer">
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick" :lazy="true">
        <el-tab-pane label="基础信息" name="1"><baseInfo :data="tableRow"/></el-tab-pane>
        <el-tab-pane label="BOM组成" name="2"><BOMForm :data="BOMFormData" /></el-tab-pane>
        <el-tab-pane label="计划分解" name="3"><planDecomposition :data="planDecompositionData" @handleClick="handleClick" /></el-tab-pane>
        <!-- <el-tab-pane label="生产产品" name="4"></el-tab-pane> -->
        <el-tab-pane label="物料明细" name="5"><materialDetails :data="materialDetailsData" /></el-tab-pane>
      </el-tabs>
    </div>

    <!-- 添加或修改生产工单对话框 -->
    <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="生产计划编号" prop="planCode" label-width="120px">
              <el-input v-model="form.planCode" :disabled="form.id?true:false" placeholder="请输入生产计划编号" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item  label-width="80">
              <el-switch 
                :disabled="form.planCode != null"
                v-model="autoGenFlag"
                active-color="#13ce66"
                active-text="自动生成"
                @change="handleAutoGenChange(autoGenFlag)" v-if="optType != 'view'">               
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产计划名称" prop="planName" label-width="120px">
              <el-input v-model="form.planName" placeholder="请输入生产计划名称" />
            </el-form-item>
          </el-col>          
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="来源类型" prop="orderSource">              
              <el-radio-group v-model="form.orderSource" disabled v-if="optType=='view'">
                <el-radio
                  v-for="dict in dict.type.mes_workorder_sourcetype"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
              <el-radio-group v-model="form.orderSource" disabled v-else>
                <el-radio
                  v-for="dict in dict.type.mes_workorder_sourcetype"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>                    
          <el-col :span="8" v-if="form.orderSource == 'ORDER'">
            <el-form-item label="订单编号" prop="orderCode">
              <el-input v-model="form.orderCode" placeholder="请输入订单编号" >
                <el-button slot="append" @click="handleSelectProduct1" icon="el-icon-search"></el-button>
              </el-input>
              <productionOrderSelect ref="itemSelect1" @onSelected="onItemSelected1" > </productionOrderSelect>
            </el-form-item>
          </el-col>         
          <el-col :span="8">
            <el-form-item label="产品编号" prop="proCode">
              <el-input v-model="form.proCode" placeholder="请选择产品" >
                <el-button slot="append" @click="handleSelectProduct" icon="el-icon-search"></el-button>
              </el-input>
              <ItemSelect ref="itemSelect" v-if="showItemSelect" @onSelected="onItemSelected" @closeSelect="showItemSelect=false"> </ItemSelect>
            </el-form-item>
          </el-col> 
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="规格型号" prop="productSpc">
              <el-input v-model="form.productSpc" placeholder="请选择产品" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="proName">
              <el-input v-model="form.proName" placeholder="请选择产品" disabled/>
            </el-form-item>
          </el-col> 
          <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input v-model="form.unitOfMeasure" placeholder="请选择产品" disabled/>
            </el-form-item>
          </el-col>          
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="开工日期" prop="startTime">
              <el-date-picker clearable
                v-model="form.startTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择完工日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="完工日期" prop="endTime">
              <el-date-picker clearable
                v-model="form.endTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择完工日期">
              </el-date-picker>
            </el-form-item>
          </el-col>    
          <el-col :span="8">
            <el-form-item label="需求日期" prop="deadLine">
              <el-date-picker clearable
                v-model="form.deadLine"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择需求日期">
              </el-date-picker>
            </el-form-item>
          </el-col>      
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划数量" prop="planCount">
              <el-input-number :min="0" v-model="form.planCount" placeholder="请输入计划数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="border-card" v-if="form.id != null">   
        <el-tab-pane label="BOM组成"> 
          <!-- <Workorderbom v-if="open" ref="bomlist" :optType="optType" :itemId="form.proId" :workorder="form" @handleAddSub="handleSubAdd" ></Workorderbom>         -->
          <ItemBom :optType="optType" :isPlan="true" :itemId="form.proId" />
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel" v-if="optType =='view' ">返回</el-button>
        <el-button type="primary" @click="submitForm" v-if="optType !='view' ">保 存</el-button>
        <!-- <el-button type="success" @click="handleConfirm" v-if="optType !='view'  && form.id !=null">确 认</el-button> -->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { 
  listWorkorder, 
  getWorkorder, 
  delWorkorder,
  closePlan,
  decomposePlan,
  finishPlan,
  withdrawPlan, 
  addWorkorder, 
  updateWorkorder, 
  dofinish,
  listProPlanProductBOM,
  listProPlanMaterielDetail,
  listProPlanWorkOrder,
} from "@/api/mes/pro/productionPlan";
import Workorderbom from "../workorder/bom/bom.vue";
import ItemBom from "../../md/mditem/components/itembom.vue";
import WorkorderItemList from "../workorder/items/item.vue";
import ItemSelect  from "@/components/itemSelect/single.vue";
import productionOrderSelect  from "@/components/productionOrderSelect";
import ClientSelect from "@/components/clientSelect/single.vue";
import VendorSelect from "@/components/vendorSelect/single.vue";
import {genCode} from "@/api/system/autocode/rule"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import dorpTable from '@/components/dorptable/index.vue'

import OverView from "../overview";

import baseInfo from './components/baseInfo.vue'
import BOMForm from './components/BOMForm.vue'
import planDecomposition from './components/planDecomposition.vue'
import yieldAProduct from './components/yieldAProduct.vue'
import materialDetails from './components/materialDetails.vue'

export default {
  name: "Workorder",
  dicts: ['mes_order_status','mes_workorder_sourcetype','mes_workorder_type', 'plan_status'],
  components: {
    Treeselect,
    ItemSelect ,
    ClientSelect,
    VendorSelect,
    Workorderbom,
    WorkorderItemList,
    OverView,
    dorpTable,
    productionOrderSelect,
    ItemBom,

    baseInfo,
    BOMForm,
    planDecomposition,
    yieldAProduct,
    materialDetails,
  },
  data() {
    return {
      showItemSelect: false,
      //自动生成编码
      autoGenFlag:false,
      optType: undefined,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 非单个禁用
      single: true,
      // 总条数
      total: 0,
      // 非多个禁用
      multiple: true,
      // 生产工单表格数据
      workorderList: [],
      // 生产工单树选项
      workorderOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planCode:null,
        planName:null,
        proCode:null,
        proName:null,
        workorderType:null,
        deadLine:null,
        unitOfMeasure: null,
      },
      // 表单参数
      form: {
        planName: null,
        startTime: null,
      },
      // 表单校验
      rules: {
        planCode: [
          { required: true, message: "工单编码不能为空", trigger: "blur" }
        ],
        planName: [
          { required: true, message: "工单名称不能为空", trigger: "blur" }
        ],
        workorderType: [
          { required: true, message: "请选择生产工单类型", trigger: "blur" }
        ],
        orderSource: [
          { required: true, message: "来源类型不能为空", trigger: "blur" }
        ],
        proId: [
          { required: true, message: "产品不能为空", trigger: "blur" }
        ],
        proCode: [
          { required: true, message: "产品编号不能为空", trigger: "blur" }
        ],
        proName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" }
        ],
        planCount: [
          { required: true, message: "生产数量不能为空", trigger: "blur" }
        ],
        deadLine: [
          { required: true, message: "需求日期不能为空", trigger: "blur" }
        ],
      },
      tableData: [],
      tableRow: [], //选中行
      activeName: "1",
      checkWorkData: [],
      planDecompositionData: [],
      rtIssueWorkData: [],
      BOMFormData: [],
      materialDetailsData: [],
      columnConfig: {
        drag: true,
        resizable: true,
        storage: true,
        sortConfig: {
          trigger: 'cell',
          remote: true
        },
        align: 'center',
        headerAlign: 'center'
      },
      rowConfig: {
        drag: true,
        keyField: 'id',
        isHover: true,
        isCurrent: true,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    selectRowEvent () {
      const $table = this.$refs.tableRef
      if ($table) {
        $table.setCurrentRow(this.tableData[0])
      }
    },
    /** 查询生产工单列表 */
    getList() {
      this.loading = true;
      this.tableData = [];
      listWorkorder(this.queryParams).then(response => {
        // this.workorderList = this.handleTree(response.rows, "workorderId", "parentId");
        if(response.rows){
          this.tableRow = response.rows[0];
        }else{
          this.tableRow = {};
        }
        this.tableData = response.rows??[];
        this.selectRowEvent()
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 转换生产工单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.workorderId,
        label: node.planName,
        children: node.children
      };
    },
	/** 查询生产工单下拉树结构 */
    // getTreeselect() {
    //   listWorkorder().then(response => {
    //     this.workorderOptions = [];
    //     const data = { workorderId: 0, planName: '顶级节点', children: [] };
    //     data.children = this.handleTree(response.data, "workorderId", "parentId");
    //     this.workorderOptions.push(data);
    //   });
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        planCode: null,
        planName: null,
        orderSource: 'STORE',
        proId: null,
        proCode: null,
        proName: null,
        orderId: null,
        orderCode: null,
        orderName: null,
        planStatusDesc: null,
        unitOfMeasure: null,
        planCount: null,
        deadLine: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.autoGenFlag = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        planCode:null,
        planName:null,
        proCode:null,
        proName:null,
        workorderType:null,
        deadLine:null,
        unitOfMeasure: null,
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //从BOM行中直接新增
    handleSubAdd(row){
      this.open = false;
      this.reset();
      this.getTreeselect();
      if (row != null && row.id) {
        this.form = row;
        this.form.parentId = row.workorderId;
        this.form.workorderId = null;
        this.form.planCode = null;
      } else {
        this.form.parentId = 0;
      }
      this.open = true;
      this.title = "添加生产工单";
      this.optType="add";
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.open = true;
      this.title = "添加生产计划";
      this.optType="add";
      this.form.planName = this.parseTime(Date.now(),'{y}-{m}-{d}');
      this.$set(this.form, 'startTime', this.parseTime(Date.now(),'{y}-{m}-{d}'));
      // this.form.startTime = this.parseTime(Date.now(),'{y}-{m}-{d}');
      console.log(this.form.planName);
      this.autoGenFlag = true
      this.handleAutoGenChange(this.autoGenFlag)
    },
    // 查询明细按钮操作
    handleView(row){
      this.reset();
      this.getTreeselect();
      const workorderId = row.workorderId || this.ids;
      getWorkorder(workorderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看工单信息";
        this.optType = "view";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form = {...row};
      this.open = true;
      this.title = "修改生产计划";
      this.optType="edit";
      console.log(row);
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form);
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWorkorder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              // this.$refs["bomlist"].getList();
              this.getList();
            });
          } else {
            addWorkorder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.form.workorderId = response.data;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除生产计划单编号为"' + row.planCode + '"的数据项？').then(function() {
        return delWorkorder(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleSelectProduct(){
      this.showItemSelect = true;
      this.$nextTick(()=>{
        this.$refs.itemSelect.showFlag = true;
      })
    },
    handleSelectProduct1(){
      this.$refs.itemSelect1.showFlag = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mes/pro/plan/export', {
        ...this.queryParams
      }, `workorder_${new Date().getTime()}.xlsx`)
    },
    handleConfirm(){
      console.log(this.form);
      let that = this;
      this.$modal.confirm('是确认完成工单编制？【确认后将不能更改】').then(function(){
        // that.form.status = 'CONFIRMED';
        that.submitForm();
      });
    },
    handleFinish(row){
      const workorderIds = row.id || this.ids;
      this.$modal.confirm('确认完成工单？一旦完成，此工单将无法继续报工').then(function() {
        return dofinish(workorderIds) //完成工单
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("更改成功");
      }).catch(() => {});
    },
    //物料选择弹出框
    onItemSelected(obj){
        if(obj != undefined && obj != null){
          this.form.proId = obj.itemId;
          this.form.proCode = obj.itemCode;
          this.form.proName = obj.itemName;
          this.form.productSpc = obj.specification;
          this.form.unitOfMeasure = obj.unitOfMeasure;  
        }
    },
    //物料选择弹出框
    onItemSelected1(obj){
      console.log(obj);
      if(obj != undefined && obj != null){
        this.form.orderId = obj.id;
        this.form.orderCode = obj.orderCode;
        this.form.orderName = obj.orderName;
      }
    },
    //客户选择弹出框
    onClientSelected(obj){
        if(obj != undefined && obj != null){
          this.form.clientId = obj.clientId;
          this.form.clientCode = obj.clientCode;
          this.form.clientName = obj.clientName;
        }
    },
    //供应商选择
    handleSelectVendor(){
      this.$refs.vendorSelect.showFlag = true;
    },
    //供应商选择弹出框
    onVendorSelected(obj){
        //debugger;
        if(obj != undefined && obj != null){
          this.form.vendorId = obj.vendorId;
          this.form.vendorCode = obj.vendorCode;
          this.form.vendorName = obj.vendorName;
        }
    },
    //自动生成编码
    handleAutoGenChange(autoGenFlag){
      if(autoGenFlag){
        genCode('WORKORDER_CODE').then(response =>{
          this.form.planCode = response;
        });
      }else{
        this.form.planCode = null;
      }
    },
    // 分解
    handleDecomposePlan(row){
      this.$modal.confirm('确认分解计划单？').then(function() {
        return decomposePlan(row.id)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("更改成功");
      }).catch(() => {});
    },
    // 撤销
    handleWithdrawPlan(row){
      this.$modal.confirm('确认撤销计划单？').then(function() {
        return withdrawPlan(row.id)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("更改成功");
      }).catch(() => {});
    },
    // 关闭
    handleClosePlan(row){
      this.$modal.confirm('确认关闭计划单？').then(function() {
        return closePlan(row.id)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("更改成功");
      }).catch(() => {});
    },
    // 完成
    handleFinishPlan(row){
      this.$modal.confirm('确认完成计划单？').then(function() {
        return finishPlan(row.id)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("更改成功");
      }).catch(() => {});
    },
    // 行点击事件
    handleRowClick(row){
      this.tableRow = { ...row.row };
      this.activeName = '1';
      this.$nextTick(() => {
        this.$refs.tableRef.setCurrentRow(row.row)
      })
      console.log(row,')))))');
    },
    handleClick(tab, event) {
      switch (tab.name) {
        case '1':
          console.log('基础信息');
          break;
        case '2':
          listProPlanProductBOM(this.tableRow.id).then(response =>{
            this.BOMFormData = response.data;
            console.log('&&&',this.buildTree(response.data));
          })
          console.log('2');
          break;
        case '3':
          listProPlanWorkOrder(this.tableRow.id).then(response =>{
            this.planDecompositionData = response.data;
            console.log(response);
          })
          console.log('3');
          break;
        case '4':

          console.log('4');
          break;
        case '5':
          listProPlanMaterielDetail(this.tableRow.id).then(response =>{
            this.materialDetailsData = response.data;
            console.log(response);
          })
          console.log('5');
          break;
        default:
          break;
      }
    },
  }
};
</script>

<style lang="scss" scoped>
.app-container{
  &-title{
    margin-bottom: 10px;
  }
}
</style>
